package com.jml.手写日志框架.controller;

import ch.qos.logback.classic.AsyncAppender;
import com.jml.手写日志框架.utils.LogBlockingQueue;
import com.jml.手写日志框架.utils.LogException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Slf4j
public class PayController {
    /**
     * toPay
     *
     * @return
     */
    @RequestMapping("/toPay")
    public String toPay(String payId, String payMoney) {
        // 记录日志到硬盘
        String payLog = System.currentTimeMillis() + "," + payId + "," + payMoney;
        boolean result = LogBlockingQueue.addLog(payLog);
        //这个就是防止队列满了，日志丢失，所以使用用户线程去写日志。
        if (!result) {
            LogException.writeErrorMsg(payLog);
        }
        //直接业务线程写日志文内容
//        LogException.writeErrorMsg(payLog);
        log.info("采用业务线程同步方式写入日志:{}", payLog);
        return "success";
    }

    public static void main(String[] args) {
        AsyncAppender a = null;
    }
}
